<template>
  <div class="saech_filer_box">
    <el-form v-init-screen-h="220"
             ref="form"
             :model="searchForm"
             label-position="top"
             label-width="auto"
             :inline="false"
             size="small">
      <el-row :gutter="20">
        <el-col :span="24"
                :offset="0"
                style="margin-bottom: 10px">筛选</el-col>
        <el-col :span="24"
                :offset="0">
          <el-form-item label="设备名称"
                        prop="deviceName">
            <el-select v-model="searchForm.deviceName"
                       class="w100"
                       clearable
                       collapse-tags
                       filterable
                       placeholder="请选择"
                       size="mini"
                       value-key="name">
              <el-option v-for="item in deviceList"
                         :key="item.name"
                         :label="item.name"
                         :value="item.name" />
            </el-select> </el-form-item></el-col>
        <el-col :span="24"
                :offset="0">
          <el-form-item label="设备Token"
                        prop="deviceToken">
            <el-select v-model="searchForm.deviceToken"
                       class="w100"
                       clearable
                       collapse-tags
                       filterable
                       placeholder="请选择"
                       size="mini"
                       value-key="name">
              <el-option v-for="item in deviceList"
                         :key="item.token"
                         :label="item.token"
                         :value="item.token" />
            </el-select> </el-form-item></el-col>
        <el-col :span="24"
                :offset="0">
          <el-form-item label="设备描述"
                        prop="deviceDes">
            <el-input v-model="searchForm.deviceDes"
                      placeholder="请输入"
                      size="small"
                      clearable></el-input> </el-form-item></el-col>

        <el-col :span="24"
                :offset="0">
          <el-form-item label="日期：">
            <el-date-picker class="w100"
                            v-model="dateArr"
                            type="datetimerange"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            align="right"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            :default-time="['00:00:00', '00:00:00']"
                            size="mini">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="search_btns flex-x flex-space">
      <el-button style="width: 49%"
                 class="reset"
                 size="mini"
                 @click="reSet">重置</el-button>
      <el-button style="width: 49%"
                 class="submit"
                 size="mini"
                 type="primary"
                 @click="submitForm">提交</el-button>
    </div>
  </div>
</template>

<script>
import { currentDate3 } from "@/utils/currentDate"
import _ from "lodash";
export default {
  props: {
    deviceList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      dateArr: [],
      searchForm: {
        deviceDes: "",
        deviceName: "",
        deviceToken: "",
        startDate: "",
        endDate: ""
      }
    };
  },
  computed: {},
  mounted() { },
  methods: {
    // 重置
    reSet() {
      this.searchForm = {
        deviceDes: "",
        deviceName: "",
        deviceToken: "",
        startDate: "",
        endDate: ""
      };
      this.dateArr = [];
      this.$emit("setFilterList");
    },
    submitForm() {
      if (
        this.searchForm.deviceDes ||
        this.searchForm.deviceName ||
        this.searchForm.deviceToken ||
        this.searchForm.batchNumber ||
        this.dateArr.length
      ) {
        this.$emit("setFilterList", {
          ...this.searchForm,
          startDate: this.dateArr.length ? currentDate3(this.dateArr[0]) : "",
          endDate: this.dateArr.length ? currentDate3(this.dateArr[1]) : ""
        });
      } else {
        this.$emit("setFilterList");
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.saech_filer_box {
  position: relative;
  height: 100%;
  /deep/.el-form-item {
    margin-bottom: 10px;
    .el-form-item__label {
      padding-bottom: 0 !important;
    }
  }
  .search_btns {
    width: 100%;
    position: absolute;
    bottom: 0;
    padding: 10px;
    left: 0;
  }
}
</style>
